﻿using System.Collections.Generic;

using JetBlack.TopicBus.Adapters;
using System;
using System.Net;

namespace ExamplePublisher
{
    class Program
    {
        static void Main(string[] args)
        {
            Client client = new Client();

            // Attempt to connect.
            try
            {
                // Assume the Distributor is running on the local machine.
                client.Connect(Dns.GetHostName(), 9122);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed to connect to distributor: {0}", ex.Message);
                Environment.Exit(-1);
            } 

            Dictionary<string, object> data = new Dictionary<string, object>();
            data["bool"] = true;
            data["char"] = 'X';
            data["byte"] = (byte)35;
            data["short"] = (short)12345;
            data["int"] = 567890;
            data["long"] = 1234567890L;
            data["float"] = 21.5F;
            data["double"] = 35.4;
            data["date"] = new DateTime(1999, 5, 18, 10, 30, 12, 10, DateTimeKind.Local);
            data["string"] = "Hello";
            data["array"] = new object[] { 1, "two", 3.0 };

            IDictionary<string, object> values = new Dictionary<string, object>();
            values["one"] = 1;
            values["two"] = 2.0;
            data["dict"] = values;

            client.Publish("LSE.FOO", true, data);

            client.Close();
        }
    }
}
